package com.example.myglidedemo.options;

import android.graphics.Bitmap;

import androidx.annotation.NonNull;

import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.annotation.GlideExtension;
import com.bumptech.glide.annotation.GlideOption;
import com.bumptech.glide.annotation.GlideType;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.BaseRequestOptions;
import com.bumptech.glide.request.RequestOptions;
import com.example.myglidedemo.R;

import jp.wasabeef.glide.transformations.BitmapTransformation;
import jp.wasabeef.glide.transformations.BlurTransformation;

//来实现我们想要的API
@GlideExtension
public final class MyGlideExtension {
    private MyGlideExtension(){

    }
    @GlideOption
    public static BaseRequestOptions<?> applyAvatar(BaseRequestOptions<?> options,int size){
        // 高斯模糊效果,这里用了第三方库
        BlurTransformation transformation = new BlurTransformation(25,2);

        return options.placeholder(R.mipmap.img_avatar_default)
                .error(R.mipmap.img_avatar_default)
                .override(size)
                .centerCrop()
                .transform(transformation) // 动画效果
                //.circleCrop() // 底层也是 transformation,两个冲突，所以
                // 默认提供了三种裁切方式
                //.fitCenter()
                //.centerCrop()
                .transform(new MultiTransformation<>(transformation,new CircleCrop()));

    }
    //
    private static final RequestOptions DECODE_TYPE_GIF=GlideOptions.decodeTypeOf(GifDrawable.class).lock();
    @NonNull
    @GlideType(GifDrawable.class)
    public static RequestBuilder<GifDrawable> MyasGif(RequestBuilder<GifDrawable> requestBuilder){
        return requestBuilder
                .transition(new DrawableTransitionOptions())
                .apply(DECODE_TYPE_GIF);
    }
    @NonNull
    @GlideType(Bitmap.class)
    public static RequestBuilder<Bitmap> MycrossFade(RequestBuilder<Bitmap> requestBuilder){
        return requestBuilder.transition(BitmapTransitionOptions.withCrossFade());// 淡入动画
    }


}
